package prod_line

import "github.com/sigurn/crc8"

func Crc(payload []byte) (crc byte) {
	var p = crc8.CRC8_MAXIM
	table := crc8.MakeTable(p)
	crc = crc8.Checksum(payload, table)
	return
}

func BuildPacket(cmd byte, body []byte) (packet []byte) {

	var packetLen = len(body)
	// cmd, len
	packet = append(packet, cmd, byte(packetLen))

	// body
	packet = append(packet, body...)

	// crc
	var crc = Crc(packet)
	packet = append(packet, crc)
	return
}
